# Makefile
#
# Created on: 2012-02-06
#     Author: Huabo Zheng
# @Copyright: 2012, www.netgear.com Inc. All rights reserved.
#make X86=1 ENABLE_LIB_NCURSES=1
#export LD_LIBRARY_PATH=../prj_file/eclipse_cdt/Debug:../../gmock/lib/.libs:../../gmock/gtest/lib/.libs:/usr/local/lib:.

DYNLIB=liblcdappframework.so
BUILD_ROOT=.


ifdef X86
CC = gcc
CXX = g++
else
CC = mips64-octeon-linux-gnu-gcc -mabi=n32
CXX = mips64-octeon-linux-gnu-g++ -mabi=n32
endif

INC_DIRS = -I../include -I../include/lcd -I/usr/include
LD_DIRS = -L/usr/local/lib

ifndef X86
INC_DIRS += -I/usr/local/include
LD_DIRS += -L/usr/local/lib
endif

LIBS ?= -lpthread
DEBUG_FLAGS ?= -g
OPTIMIZE_FLAG ?= -O0
GCOV_FLAGS =  -fprofile-arcs -ftest-coverage
DYNLIBFLAGS = -shared -fPCI
CXXFLAGS ?= $(DEBUG_FLAGS) $(OPTIMIZE_FLAG) -DHAVE_INTTYPES_H


ifdef ENABLE_LIB_NCURSES
LIBS += -lncurses
CXXFLAGS += -DENABLE_LIB_NCURSES
endif



SOURCE_FILES = $(shell find $(BUILD_ROOT) -name "*.cpp")

SOURCE_DIRS = $(dir $(SOURCE_FILES))
OBJECT_DIRS = $(patsubst %.cpp,%.o,${SOURCE_FILES})
OBJECT_NAME = $(notdir $(OBJECT_DIRS))

OBJECT_TEMP ?= $(BUILD_ROOT)/../obj

OBJECT_PATH =  $(addprefix $(OBJECT_TEMP)/,$(OBJECT_DIRS))
OBJECT_FILES = $(addprefix $(OBJECT_TEMP)/,$(OBJECT_NAME))

OUTPUT_DIR ?= $(BUILD_ROOT)/../lib

all: $(DYNLIB)

OBJ_PATH:
	@mkdir $(OBJECT_TEMP)

 
${DYNLIB}: ${OBJECT_DIRS}
	@echo "(LD) $(OUTPUT_DIR)/$@"
	@$(CXX) $(OBJECT_FILES) $(CXXFLAGS) $(DYNLIBFLAGS) $(LDFLAGS) $(INC_DIRS) $(LD_DIRS) -o $(OUTPUT_DIR)/$@ $(LIBS)


$(OBJECT_DIRS):%.o:%.cpp
	@echo "$(CXX) $(notdir $<) -> $(OBJECT_TEMP)/$(notdir $@)"
	@$(CXX) $(CXXFLAGS) $(INC_DIRS) -c -o $(OBJECT_TEMP)/$(notdir $@) $<
 
 
.PHONY: clean
clean:
	@echo "rm -rf $(OBJECT_FILES)"
	@rm -rf $(OBJECT_FILES)
	@echo "rm -rf $(OBJECT_TEMP)/*.o"
	@rm -rf $(OBJECT_TEMP)/*.o
	@echo "rm -rf $(OUTPUT_DIR)/$(DYNLIB) $(DEP_FILES) $(GCOV_FILES)"
	@rm -rf $(OUTPUT_DIR)/$(DYNLIB) $(DEP_FILES) $(GCOV_FILES) 


